
'''此文件用于分隔文件'''
def split_txt(file_path):
    '''文件'''
    f_news_culture =open('split_data/news_culture.txt',mode='w',encoding='utf-8')
    f_news_entertainment = open('split_data/news_entertainment.txt',mode='w',encoding='utf-8')
    f_news_sports = open('split_data/news_sports.txt',mode='w',encoding='utf-8')
    f_news_finance = open('split_data/news_finance.txt',mode='w',encoding='utf-8')
    f_news_house = open('split_data/news_house.txt',mode='w',encoding='utf-8')
    f_news_car = open('split_data/news_car.txt',mode='w',encoding='utf-8')
    f_news_edu = open('split_data/news_edu.txt',mode='w',encoding='utf-8')
    f_news_tech = open('split_data/news_tech.txt',mode='w',encoding='utf-8')
    f_news_military= open('split_data/news_military.txt',mode='w',encoding='utf-8')
    f_news_travel= open('split_data/news_travel.txt',mode='w',encoding='utf-8')
    f_news_world= open('split_data/news_world.txt',mode='w',encoding='utf-8')
    f_news_agriculture= open('split_data/news_agriculture.txt',mode='w',encoding='utf-8')
    f_news_game= open('split_data/news_game.txt',mode='w',encoding='utf-8')
    '''统计数据，定制编号'''
    num_news_culture=1
    num_news_entertainment=1
    num_news_sports=1
    num_news_finance=1
    num_news_house=1
    num_news_car=1
    num_news_edu=1
    num_news_tech=1
    num_news_military=1
    num_news_travel=1
    num_news_world=1
    num_news_agriculture=1
    num_news_game=1
    '''读取总数据，进行分类存储'''
    print("Split begin!")
    with open(file_path,encoding='utf-8') as f:
        for line in f.readlines():
            data=line.split('_!_')
            if data[2] == 'news_culture':
                culture_string = [str(num_news_culture)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_culture.writelines(culture_string)
                num_news_culture+=1
                
            if data[2] == 'news_entertainment':
                entertainment_string = [str(num_news_entertainment)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_entertainment.writelines(entertainment_string)
                num_news_entertainment+=1
                
            if data[2] == 'news_sports':
                sports_string = [str(num_news_sports)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_sports.writelines(sports_string)
                num_news_sports+=1
                
            if data[2] == 'news_finance':
                fiance_string = [str(num_news_finance)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_finance.writelines(fiance_string)
                num_news_finance+=1
                
            if data[2] == 'news_house':
                house_string = [str(num_news_house)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_house.writelines(house_string)
                num_news_house+=1
                
            if data[2] == 'news_car':
                car_string = [str(num_news_car)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_car.writelines(car_string)
                num_news_car+=1
                
            if data[2] == 'news_edu':
                edu_string = [str(num_news_edu)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_edu.writelines(edu_string)
                num_news_edu+=1
                
            if data[2] == 'news_tech':
                tech_string = [str(num_news_tech)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_tech.writelines(tech_string)
                num_news_tech+=1
            
            if data[2] == 'news_military':
                military_string = [str(num_news_military)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_military.writelines(military_string)
                num_news_military+=1
                
            if data[2] == 'news_travel':
                travel_string = [str(num_news_travel)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_travel.writelines(travel_string)
                num_news_travel+=1
    
            if data[2] == 'news_world':
                world_string = [str(num_news_world)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_world.writelines(world_string)
                num_news_world+=1
                
            if data[2] == 'news_agriculture':
                agriculture_string = [str(num_news_agriculture)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_agriculture.writelines(agriculture_string)
                num_news_agriculture+=1
                
            if data[2] == 'news_game':
                game_string = [str(num_news_game)+'\t',data[2]+'\t',data[3]+'，'+data[4]]
                f_news_game.writelines(game_string)
                num_news_game+=1
            data = []
    f_news_culture.close()
    f_news_entertainment.close()
    f_news_sports.close()
    f_news_finance.close()
    f_news_house.close()
    f_news_car.close()
    f_news_edu.close()
    f_news_tech.close()
    f_news_military.close()
    f_news_travel.close()
    f_news_agriculture.close()
    f_news_world.close()
    f_news_game.close()
    print("Splict over!")